<%--
  Created by IntelliJ IDEA.
  User: FENG1
  Date: 2022/5/20
  Time: 8:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>修改库存信息</title>
    <link href="static/component/pear/css/pear.css" rel="stylesheet" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <input type="hidden" name="stockId" value="${st.stockId}"><%--库存id--%>
            <%--<input type="hidden" name="goodsid" value="${st.goodsid}">--%><%--商品外键--%>
            <%--<input type="hidden" name="stockId" value="${st.stockId}">--%><%--库存id--%>
            <%--<input type="hidden" name="Yreponseid" value="${st.reponseid}">--%><%--原仓库id--%>
            <%--<input type="hidden" name="YstockCount" value="${st.stockCount}">--%><%--原商品库存数量--%>
            <input type="hidden" name="capacity" value="${st.capacity}"><%--商品的所占容量--%>
            <div class="layui-form-item">
                <label class="layui-form-label">所属仓库</label>
                <div class="layui-input-block">
                    <select name="reponseid" class="layui-input">
                        <c:forEach items="${reps}" var="r">
                            <option value="${r.reponseTypePid}">${r.reponseTypeName}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">库存数量</label>
                <div class="layui-input-block">
                    <input type="text" name="stockCount" id="stockCount" value="${st.stockCount}" lay-verify="number"  lay-verify="title" autocomplete="off"
                           placeholder="请输入库存数量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">预警值</label>
                <div class="layui-input-block">
                    <input type="text" name="stockwarnCount" id="stockwarnCount" value="${st.stockwarnCount}"  lay-verify="number"  lay-verify="title" autocomplete="off"
                           placeholder="请输入预警值" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属品牌</label>
                <div class="layui-input-block">
                    <select name="supplierid" class="layui-input">
                        <c:forEach items="${supp}" var="s">
                            <option value="${s.supplierId}">${s.supplierName}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" id="TiJ" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
    $("[name='reponseid']").val("${st.reponseid}");
    $("[name='supplierid']").val("${st.supplierid}");
</script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        $('#stockCount').bind('input propertychange', function() {
            $.post("/inventory/upJaoyan",$(".layui-form").serialize(),function(result){
                if(result.success){
                    $('#TiJ').removeClass("layui-btn-disabled").attr("disabled",false);
                }else{
                    $('#TiJ').addClass("layui-btn-disabled").attr("disabled",true);
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            })
        })
        $("#stockwarnCount").bind('input propertychange', function() {
            if($("#stockwarnCount").val() <1){
                $('#TiJ').addClass("layui-btn-disabled").attr("disabled",true);
            }else{
                $('#TiJ').removeClass("layui-btn-disabled").attr("disabled",false);
                //$("#stockwarnCount").focus();
            }
        })
        /*$("#stockCount").blur(function(){//给库存数量绑定失去焦点事件 以及判断仓库可存储的库存数量
            $.post("/inventory/upJaoyan",$(".layui-form").serialize(),function(result){
               if(result.success){
                   $('#TiJ').removeClass("layui-btn-disabled").attr("disabled",false);
               }else{
                   $('#TiJ').addClass("layui-btn-disabled").attr("disabled",true);
                   layer.msg(result.msg,{icon:2,time:1000});
               }
            })
        })*/
        form.on('submit(user-save)', function(data){
            $.post("/inventory/upInventory",data.field,function (result) {
                if(result.success){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        window.close();
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("currentTableId");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            })
        });
    })
</script>
</body>
</html>